package com.android1.amarena2d.test;

import com.android1.amarena2d.engine.collision.Collision;
import com.android1.amarena2d.engine.collision.CollisionCallback;
import com.android1.amarena2d.nodes.FpsLabel;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.android1.amarena2d.nodes.behavior.delegates.CollisionDelegate;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.badlogic.gdx.graphics.Color;

public class CollisionExampleScene extends Scene {

    final SharedSprite sprite;
    final SharedSprite sprite2;

    public CollisionExampleScene() {

        touch().makeTouchable(this);

        engine.getRenderer().setClearColor(Color.WHITE);

        FpsLabel fpsLabel = new FpsLabel(10, 20, Color.BLACK);
        add(fpsLabel);
        add(new SimpleLabel("(Touch the Sprite to start)", 100, 20, Color.BLACK));


        sprite = new SharedSprite("assets/toad.png", 100, 100);
        sprite.collision().setOnCollision(new CollisionCallback() {
            @Override
            public void on(CollisionDelegate self,CollisionDelegate target) {
                sprite.move().stop();
                sprite.collision().revertToLastPos();
            }
        }).setVolumeBox(-10, 0, 28, 38).register();

        sprite2 = new SharedSprite("assets/toad.png", 250, 100);
        sprite2.collision().setCheckBehaviour(Collision.CheckBehaviour.Passive).setVolumeBox(-10, 0, 28, 38).register();


        add(sprite, sprite2);
    }

    @Override
    public boolean onTouchUp(float x, float y, int pointer, boolean isHit) {
        sprite.setXY(x, y);
        sprite.move().by(200, 0, 3);
        return true;
    }
}